package com.corn.turtorial.consumer.controller;

import com.corn.turtorial.consumer.mapper.Point;
import com.corn.turtorial.consumer.mapper.PointMapper;
import com.corn.turtorial.consumer.service.PointService;
import io.seata.core.context.RootContext;
import io.seata.core.model.TransactionManager;
import io.seata.spring.annotation.GlobalTransactional;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.transaction.annotation.Transactional;
import org.springframework.web.bind.annotation.RestController;

import java.util.HashMap;
import java.util.Map;

/**
 * @author : Jim Wu
 * @version 1.0
 * @function :
 * @since : 2022/5/5 11:19
 */

@RestController
@Slf4j
public class PointController implements PointService {
    @Autowired
    private PointMapper pointMapper;

    @Override
    @Transactional
    public Map<String, Object> createPoint(Point point) {
        String txId = RootContext.getXID();
        log.info("Seata全局事务id=================>{}", txId);
        pointMapper.insert(point);
        Map<String, Object> result = new HashMap<>();
        result.put("message", "success");
        int i = 1/0;
        return result;
    }
}
